package com.tj.demo.codesnip.designoatten.stategy;

/**
 * @ClassName: Soter
 * @Author: TanJun  反对法问问
 * @Date: 2021/5/25 0:54
 * @Description:
 * @Version: 1.0
 * @Copyright:
 */
public class Soter<T> {
    public void sort(T[] arr, Comparator<T> comparator){
        for (int i = 0; i < arr.length - 1; i++) {
            int min = i;
            for (int j = i + 1; j < arr.length; j++) {
                min = comparator.compara(arr[j],arr[min]) == -1 ? j : min;
            }
            swap(arr,i,min);
        }
    }

    public void swap(T[] arr, int i, int j){
        T t = arr[i];
        arr[i] = arr[j];
        arr[j] = t;
    }
}
